home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / RxSlides / RxSlidesIn.c < prev    next >
C/C++ Source or Header  |  1990-03-08  |  8KB  |  394 lines

  1. /* :bk=0 */
  2.  
  3. /****************************************************************/
  4. /*                                */
  5. /*    RxSlidesIn.c                        */
  6. /*                                */
  7. /* Author: Dean Bandes from Lee M. Robertson's "Dissolve"    */
  8. /* Rev   : Nov 6, 1988                        */
  9. /*                                */
  10. /****************************************************************/
  11.  
  12. #include "exec/types.h"
  13. #include "exec/memory.h"
  14. #include "graphics/gfx.h"
  15. #include "intuition/intuition.h"
  16. #include "storage.h"
  17. #include <stdio.h>
  18. #include "RxSlides.h"
  19. #include "RxSliPic.h"
  20.  
  21. struct NewWindow NewWindow = 
  22. {
  23.     0,                        /* left edge */
  24.     0,                          /* top edge  */
  25.     320,                        /* width     */
  26.     200,                        /* heigth    */
  27.     0,1,                        /* pen's     */
  28.     VANILLAKEY | MOUSEBUTTONS | CLOSEWINDOW,    /* IDCmpFlags */
  29.  
  30.     /* flags */
  31.     RMBTRAP | WINDOWCLOSE | BACKDROP | NOCAREREFRESH | BORDERLESS | ACTIVATE,
  32.  
  33.     0,            /* gadget list */
  34.     0,            /* check mark */
  35.     0,            /* title pointer */
  36.     0,            /* screen pointer */
  37.     0,            /* bitmap pointer */
  38.     0,0,            /* minimum sizes */
  39.     0,0,            /* maximum sizes */
  40.     CUSTOMSCREEN,
  41. };
  42.  
  43. struct NewScreen NewScreen =
  44. {
  45.     0,                /* left edge */
  46.     0,                /* top edge  */
  47.     320,                /* width     */
  48.     200,                /* heigth    */
  49.     5,                /* depth     */
  50.     0,1,                /* pen's     */
  51.     0,                /* view modes */
  52.     CUSTOMSCREEN,            /* type      */
  53.     0,                /* font      */
  54.     (UBYTE *)"Dissolve screen",    /* title     */
  55.     0,                /* gagets    */
  56.     0,                /* bitmap    */
  57. };
  58.  
  59. struct    Screen     *OpenScreen();
  60. struct    Window     *OpenWindow();
  61. struct    ViewPort *ViewPortAddress();
  62.  
  63. struct    BitMap        BitMap        = {0};    /* bitmap to read picture into */
  64. struct    picture     pic        = {0};
  65. struct    Screen           *Screen        = NULL;
  66. struct    ViewPort       *vp        = NULL;
  67. struct    Window           *Window        = NULL;
  68.  
  69. UBYTE            svcmap[CMSIZE]    = {0};
  70.  
  71. static    int    plane_depth_alloc = 0;
  72. static    int    plane_size_alloc  = 0;
  73.  
  74. /*-h-    int    show_pic (filename, speed, transition)
  75.  *
  76.  *    char *filename        name of picture file
  77.  *    LONG  speed        speed of transition
  78.  *    SHORT transition    transition type
  79.  *
  80.  *    Returns a status (0 = OK)
  81.  */
  82.  
  83. int    show_pic (filename, speed, transition)
  84.  
  85. char   *filename;
  86. LONG    speed;
  87. SHORT    transition;
  88.  
  89.   {
  90.   extern    int    pic_from_file ();
  91.   extern    int    window_for_pic ();
  92.  
  93. #ifdef DEBUG
  94.   extern    LONG    debug_level;
  95. #endif
  96.  
  97.   int    status = 0;
  98.  
  99.   status = pic_from_file ( &pic, filename );
  100.  
  101. #ifdef DEBUG
  102.   if ( debug_level > 10 )
  103.     printf ("  pic_from_file returned status %d\n", status);
  104. #endif
  105.  
  106.   if ( status != STS_OK )
  107.     return (status);
  108.   status = window_for_pic (&pic);
  109.  
  110. #ifdef DEBUG
  111.   if ( debug_level > 10 )
  112.     printf ("  window_for_pic returned status %d\n", status);
  113. #endif
  114.  
  115.   if ( status != STS_OK )
  116.     {
  117.     free_planes_alloc ();
  118.     return (status);
  119.     }
  120.  
  121.   if ( transition < 0 )
  122.     {
  123. #ifdef DEBUG
  124.     if ( debug_level > 10 )
  125.       printf ("  transition clipped from %d to 0\n", transition);
  126. #endif
  127.     transition = 0;
  128.     }
  129.  
  130.   if ( transition > MAX_TRANSITION )
  131.     {
  132. #ifdef DEBUG
  133.     if ( debug_level > 10 )
  134.       printf ("  transition clipped from %d to %d\n",
  135.           transition,
  136.           MAX_TRANSITION);
  137. #endif
  138.     transition = MAX_TRANSITION;
  139.     }
  140.  
  141.   status = dissolve( &BitMap, Window->RPort->BitMap, speed, transition );
  142. #ifdef DEBUG
  143.   if ( debug_level > 10 )
  144.     printf ("  dissolve returned status %d\n", status);
  145. #endif
  146.  
  147.   if ( status == STS_OK )
  148.     savecolors (&svcmap[0], &pic.cmap[0]);
  149.  
  150.   free_planes_alloc ();
  151.   return (STS_OK);
  152.   }
  153.  
  154. /*-h- int pic_from_file (picpt, filename)
  155.  *
  156.  *    Read a "pic" struct from a file
  157.  */
  158.  
  159. int    pic_from_file (picpt, filename)
  160.  
  161. struct picture *picpt;
  162. char           *filename;
  163.  
  164.   {
  165.   extern int    open_pic ();
  166.   extern int    rd_bmap ();
  167.  
  168. #ifdef DEBUG
  169.   extern LONG    debug_level;
  170. #endif
  171.  
  172.   int    i;
  173.   int    psize;
  174.   int    status;
  175.  
  176.   if( status = open_pic( filename, picpt ))
  177.     {
  178. #ifdef DEBUG
  179.     if ( debug_level > 10 )
  180.       printf ("open_pic status %d: %s\n", status, filename);
  181. #endif
  182.     return( status );
  183.     }
  184.  
  185. /* setup the temp bitmap for the data */
  186.  
  187.   BitMap.BytesPerRow    = (picpt->bmhd.w >> 4) << 1;
  188.   BitMap.Rows        = picpt->bmhd.h;
  189.   BitMap.Depth        = picpt->bmhd.nPlanes;
  190.  
  191.   psize = BitMap.BytesPerRow * BitMap.Rows;    /* calculate the plane size */
  192.  
  193.   if( psize == 0 || picpt->bmhd.nPlanes > 6 )
  194.     {
  195. #ifdef DEBUG
  196.     if ( debug_level > 10 )
  197.       printf ("Invalid parameters: %s\n", filename);
  198. #endif
  199.     return( STS_BAD_PSIZE );
  200.     }
  201.  
  202. /* Allocate memory for plane data */
  203.   plane_size_alloc = psize;
  204.  
  205.   for( i=0; i<BitMap.Depth; i++ )
  206.     {
  207.     if( (BitMap.Planes[i] = (UBYTE *) AllocMem( psize, MEMF_CHIP)) == 0 )
  208.       {
  209.       free_planes_alloc ();
  210. #ifdef DEBUG
  211.       if ( debug_level > 10 )
  212.     printf ("Unable to allocate bitmap memory in pic_from_file\n"); 
  213. #endif
  214.       return ( STS_BAD_ALLOC );
  215.       }
  216.     else
  217.       plane_depth_alloc = i + 1;
  218.     }
  219.  
  220. /* Now read the picture into the temp bitmap */
  221.   status = rd_bmap( &BitMap, picpt );
  222.  
  223.   close (picpt->fd);
  224.  
  225.   if ( status != STS_OK )
  226.     {
  227.     free_planes_alloc ();
  228. #ifdef DEBUG
  229.     if ( debug_level > 10 )
  230.       printf ("Unable to rd_bmap\n");
  231. #endif
  232.     return (status);
  233.     }
  234.  
  235.   return (STS_OK);
  236.   }
  237.  
  238. /*-h-    int    free_planes_alloc ()
  239.  */
  240.  
  241. int    free_planes_alloc ()
  242.  
  243.   {
  244.   int    i;
  245.  
  246.   for( i=0; i<plane_depth_alloc; i++ )
  247.     {
  248.     FreeMem (BitMap.Planes[i], plane_size_alloc);
  249.     BitMap.Planes[i] = NULL;
  250.     }
  251.   plane_depth_alloc = 0;
  252.   plane_size_alloc  = 0;
  253.  
  254.   return (STS_OK);
  255.   }
  256.  
  257. /*-h-    int    window_for_pic (picpt)
  258.  *
  259.  *    struct picture *picpt        pointer to picture to display
  260.  *
  261.  *    Opens a screen and window (if appropriate ones don't exist
  262.  *    to display the picture in question)
  263.  *
  264.  *    Returns a status (0 = OK)
  265.  */
  266.  
  267. int    window_for_pic (picpt)
  268.  
  269. struct picture *picpt;
  270.  
  271.   {
  272. /* check for existing screen and window that match */
  273.  
  274.   if ( Window )
  275.     {
  276.     if (( NewWindow.Width  != picpt->bmhd.w ) ||
  277.     ( NewWindow.Height != picpt->bmhd.h ))
  278.       {
  279.       CloseWindow (Window);
  280.       Window = NULL;
  281.       }
  282.     }
  283.   if ( Screen )
  284.     {
  285.     if (( NewScreen.Width != picpt->bmhd.w ) ||
  286.     ( NewScreen.Height != picpt->bmhd.h ) ||
  287.     ( NewScreen.Depth  != picpt->bmhd.nPlanes ) )
  288.       {
  289.       if ( Window )
  290.     {
  291.     CloseWindow (Window);
  292.     Window = NULL;
  293.     }
  294.       CloseScreen (Screen);
  295.       Screen = NULL;
  296.       }
  297.     }
  298.  
  299.   if ( ! Screen )
  300.     {
  301.     NewScreen.Width  = picpt->bmhd.w;
  302.     NewScreen.Height = picpt->bmhd.h;
  303.     NewScreen.Depth  = picpt->bmhd.nPlanes;
  304.  
  305.   /* set bits for display modes */
  306.     NewScreen.ViewModes = 0;
  307.     if( NewScreen.Depth == 6 && NewScreen.Width <= 320 )
  308.       NewScreen.ViewModes |= HAM;
  309.  
  310.     if( NewScreen.Height > 200 )
  311.       NewScreen.ViewModes |= LACE;
  312.  
  313.     if( NewScreen.Width > 320 )
  314.       NewScreen.ViewModes |= HIRES;
  315.  
  316.     Screen = OpenScreen( &NewScreen);
  317.     if( Screen == 0 )
  318.       {
  319. #ifdef DEBUG
  320.       if ( debug_level > 10 )
  321.     printf ("Unable to open screen\n");
  322. #endif
  323.       return (STS_NO_SCREEN);
  324.       }
  325.     }
  326.  
  327.   if ( ! Window )
  328.     {
  329.     NewWindow.Screen = Screen;
  330.     NewWindow.Width  = picpt->bmhd.w;
  331.     NewWindow.Height = picpt->bmhd.h;
  332.  
  333.     Window = OpenWindow( &NewWindow );
  334.     if( Window == 0 )
  335.       {
  336.       CloseScreen (Screen);
  337.       Screen = NULL;
  338. #ifdef DEBUG
  339.       if ( debug_level > 10 )
  340.     printf ("Unable to open window\n");
  341. #endif
  342.       return (STS_NO_WINDOW);
  343.       }
  344.  
  345.     ShowTitle( Screen, 0L );            /* hide the screen title */
  346.     vp = ViewPortAddress( Window );        /* get the windows viewport */
  347.     SetRast( Window->RPort, 0L );        /* clear the screen */
  348.  
  349.     setcolors( vp, &svcmap[0], picpt->numcolors );
  350.     }
  351.   return (STS_OK);
  352.   }
  353.  
  354. /*-h-    int    close_pic_window ()
  355.  */
  356.  
  357. int    close_pic_window ()
  358.  
  359.   {
  360.   if ( Window )
  361.     {
  362.     CloseWindow (Window);
  363.     Window = NULL;
  364.     }
  365.   if ( Screen )
  366.     {
  367.     CloseScreen (Screen);
  368.     Screen = NULL;
  369.     }
  370.   return (STS_OK);
  371.   }
  372.  
  373. /*-h-    int    pic_back ()
  374.  */
  375.  
  376. int    pic_back ()
  377.  
  378.   {
  379.   if ( Screen )
  380.     ScreenToBack ( Screen );
  381.   return (STS_OK);
  382.   }
  383.  
  384. /*-h-    int    pic_front ()
  385.  */
  386.  
  387. int    pic_front ()
  388.  
  389.   {
  390.   if ( Screen )
  391.     ScreenToFront ( Screen );
  392.   return (STS_OK);
  393.   }
  394.